import bus from "@/bus";
import { jsonPost } from '@/util'
let data = {
  form: {
    activityName: '',
    activitySn: '',
    activityStatus: null,
    activityType: null,
    activityTag: null,
    date: [],
    skuId: '',
    productSn: ''
  },
  status: 'pass',
  totalItem: 1,
  pageSize: window.$pageSize,
  currentPage: 1,
  columns: [{
    type: 'selection',
    width: 60,
    align: 'left'
  }, {
    title: '促销编码',
    key: 'activitySn',
    align: 'left',
    minWidth: 150
  }, {
    title: '活动标签',
    key: 'promotionTagName',
    align: 'left',
    minWidth: 150,
    render: (h, p) => {
      return <div>{p.row.promotionTagName || '-'}</div>
    }
  }, {
    title: '标签ID',
    key: 'promotionTagId',
    align: 'left',
    minWidth: 200,
    render: (h, p) => {
      return <div>{p.row.promotionTagId || '-'}</div>
    }
  }, {
    title: '活动名称',
    key: 'activityName',
    align: 'left',
    minWidth: 250
  }, {
    title: "促销时间",
    key: "date",
    align: "left",
    minWidth: 320,
    render: (h, params) => {
      let row = params.row
      let arr1 = row.promotionTimesDescription && row.promotionTimesDescription.split(',')
      let arr = (arr1 || []).map(item => {
        return h('p', item)
      })
      return h('div', [arr])
    }
  }, {
    title: '促销类型',
    key: 'promotionTypeDescription',
    align: "left",
    minWidth: 150
  }, {
    title: '激活限时',
    key: 'activeLimitStartTime',
    align: 'left',
    minWidth: 320,
    renderHeader: (h) => {
      let oDiv = h('div', [
        h('span', '激活限时'),
        h('Icon', {
          props: {
            type: 'ios-help-circle'
          }
        })
      ])
      return h('Tooltip', {
        style: {
          cursor: 'pointer'
        },
        props: {
          transfer: true,
          placement: 'top',
          content: '扫码入库激活优惠券、赠送返利、赠送积分等的时间限制范围',
          maxWidth: '200'
        }
      }, [oDiv])
    },
    render: (h, params) => {
      let t = params.row.factoryInfoDTO ? (params.row.factoryInfoDTO.activeLimitStartTime + '-' +  params.row.factoryInfoDTO.activeLimitEndTime) : ''
      return <div>{t || '-'}</div>
    }
  }, {
    title: "促销信息",
    key: "promotionRuleDescription",
    align: "left",
    minWidth: 150,
    render: (h, p) => {
      return <div class="e1" title={p.row.promotionRuleDescription}>{p.row.promotionRuleDescription}</div>
    }
  }, {
    title: "促销状态",
    key: "statusText",
    align: "left",
    minWidth: 100,
    fixed: 'right',
  }, {
    title: "操作",
    key: "operate",
    align: "right",
    width: 240,
    fixed: 'right',
    render: (h, params) => {
      const row = params.row;
      let editDis = true
      if ((row.statusText === '未审核' || row.statusText === '已暂停' || row.statusText === '进行中' || row.statusText === '已结束') && (row.shelfStatusEnum === "UNDER" || row.promotionTypeDescription === '工厂特价')) {
        editDis = false
      } else if (row.statusText === '已驳回' || row.promotionTypeDescription === '满额返券') {
        editDis = true
      } else if (row.statusText === '未开始' || row.statusText === '下架') {
        editDis = false
      }
      let detailBtn = h("Button", {
        props: {
          size: "small",
          type: 'primary'
        },
        style: {
          marginRight: "5px"
        },
        on: {
          click: () => {
            window.$router.push({
              name: "sales/detail",
              query: {
                id: row.id,
                type: row.activityTypeEnum
              }
            });
          }
        }
      }, "查看");
      let copyBtn = h("Button", {
        style: {
          marginRight: "5px"
        },
        props: {
          size: "small",
          type: 'primary'
        },
        on: {
          click: () => {
            let url =''
            switch (params.row.activityTypeEnum) {
              // 满减送
              case 'FULL_CUT_GIFT':
                url = 'sales/fullSubGift'
                break;
              // 满赠
              case 'FULL_GIFT':
                url = 'sales/fullGift'
                break;
              // 单品
              case 'SINGLE':
                url = 'sales/single'
                break;
              // 赠品
              case 'GIFT':
                url = 'sales/gift/rules'
                break;
              // 满减
              case 'FULL_CUT':
                url = 'sales/fullsub/rules'
                break;
              // 多买优惠
              case 'BUY_MORE':
                url = 'sales/more/rules'
                break;
              // 满额返券
              case 'FULL_COUPON':
                url = 'sales/fullReturn/rules'
                break;
              // 工厂促销
              case 'FACTORY_ACTIVITY':
                url = 'sales/bargain/rules'
                break;
            }
            // 复制活动 -- 生成一个id（和编辑功能差不多）
            if( params.row.activityTypeEnum == 'FACTORY_ACTIVITY') {
              jsonPost(`/activity/factory_info/copy/${row.id}`).then(res => {              
                window.$router.push({
                  name: url,
                  query: {
                    id: res
                  }
                })
              })
            } else {
              window.$router.push({
                name: url,
                query: {
                  id: params.row.id
                }
              })
            }
          }
        }
      }, '复制活动');
      let drop = h('Dropdown', {
        props: {
          transfer: true
        }
      }, [
        h('Button', {
          props: {
            size: "small",
            type: 'primary'
          }
        }, ['更多',
          h('Icon', {
            props: {
              type: "ios-arrow-down"
            }
          })
        ]),
        h('DropdownMenu', {
          slot: 'list'
        }, [
          h('DropdownItem', {
            props: {
              disabled: row.statusText === '已驳回'
            },
            nativeOn: {
              click:() => {
                if (row.statusText === '已驳回') return
                bus.$emit("onChangeshelfBtn", { item: row })
              }
            }
          }, row.shelfStatusEnum !== "ON" ?  "上架" : "下架"),
          h('DropdownItem', {
            props: {
              disabled: editDis
            },
            nativeOn: {
              click: () => {
                if (editDis) return
                let url =''
                switch (params.row.activityTypeEnum) {
                  // 满减送
                  case 'FULL_CUT_GIFT':
                    url = 'sales/fullSubGift'
                    break;
                  // 满赠
                  case 'FULL_GIFT':
                    url = 'sales/fullGift'
                    break;
                  // 单品
                  case 'SINGLE':
                    url = 'sales/single'
                    break;
                  // 赠品
                  case 'GIFT':
                    url = 'sales/gift/rules'
                    break;
                  // 满减
                  case 'FULL_CUT':
                    url = 'sales/fullsub/rules'
                    break;
                  // 多买优惠
                  case 'BUY_MORE':
                    url = 'sales/more/rules'
                    break;
                  // 满额返券
                  case 'FULL_COUPON':
                    url = 'sales/fullReturn/rules'
                    break;
                  // 工厂促销
                  case 'FACTORY_ACTIVITY':
                    url = 'sales/bargain/rules'
                    break;
                }
                window.$router.push({
                  name: url,
                  query: {
                    id: params.row.id,
                    type: params.row.activityTypeEnum
                  }
                })
              }
            }
          }, "修改"),
          h('DropdownItem', {
            props: {
              disabled: !(row.statusText === '已暂停' || row.statusText === '进行中')
            },
            nativeOn: {
              click:() => {
                if ((row.statusText === '已暂停' || row.statusText === '进行中')) {
                  bus.$emit("onChangePause", { item: row })
                }
              }
            }
          }, row.statusText === '已暂停' ?  "取消暂停" : "暂停"),
          h('DropdownItem', {
            props: {
              disabled: row.activityTypeEnum === 'FULL_COUPON' || row.statusText === '进行中' || row.promotionTypeDescription === '满额返券'
            },
            nativeOn: {
              click:() => {
                if (row.activityTypeEnum === 'FULL_COUPON' || row.statusText === '进行中' || row.promotionTypeDescription === '满额返券') return
                bus.$emit("onDelete", { item: row, index: params.index })
              }
            }
          }, "删除"),
          h('DropdownItem', {
            props: {
              disabled: row.statusText !== '未审核'
            },
            nativeOn: {
              click:() => {
                if (row.statusText !== '未审核') return
                window.$router.push({
                  name: "sales/detail",
                  query: {
                    id: row.id,
                    type: row.activityTypeEnum
                  }
                })
              }
            }
          }, "审核"),
          h('DropdownItem', {
            props: {
              disabled: row.statusText === '已驳回'
            },
            nativeOn: {
              click:() => {
                if (row.statusText === '已驳回') return
                window.$router.push({
                  name: "sales/statics",
                  query: {
                    id: row.id
                  }
                });
              }
            }
          }, "数据统计"),
        ])
      ])

      // let shelfBtn = h("Button", {
      //   class: 'font-blue',
      //   props: {
      //     size: "small",
      //     type: 'text'
      //   },
      //   style: {
      //     marginRight: "5px"
      //   },
      //   on: {
      //     click: () => {
      //       bus.$emit("onChangeshelfBtn", { item: row })
      //     }
      //   }
      // }, row.shelfStatusEnum !== "ON" ?  "上架" : "下架")
      // let editBtn = h("Button", {
      //   class: 'font-blue',
      //   props: {
      //     size: "small",
      //     type: 'text'
      //   },
      //   on: {
      //     click: () => {
      //       let url =''
      //       switch (params.row.activityTypeEnum) {
      //         // 满减送
      //         case 'FULL_CUT_GIFT':
      //           url = 'sales/fullSubGift'
      //           break;
      //         // 满赠
      //         case 'FULL_GIFT':
      //           url = 'sales/fullGift'
      //           break;
      //         // 单品
      //         case 'SINGLE':
      //           url = 'sales/single'
      //           break;
      //         // 赠品
      //         case 'GIFT':
      //           url = 'sales/gift/rules'
      //           break;
      //         // 满减
      //         case 'FULL_CUT':
      //           url = 'sales/fullsub/rules'
      //           break;
      //         // 多买优惠
      //         case 'BUY_MORE':
      //           url = 'sales/more/rules'
      //           break;
      //         // 满额返券
      //         case 'FULL_COUPON':
      //           url = 'sales/fullReturn/rules'
      //           break;
      //         // 工厂促销
      //         case 'FACTORY_ACTIVITY':
      //           url = 'sales/bargain/rules'
      //           break;
      //       }
      //       window.$router.push({
      //         name: url,
      //         query: {
      //           id: params.row.id,
      //           type: params.row.activityTypeEnum
      //         }
      //       })
      //     }
      //   }
      // }, '修改')
      // let pauseBtn = h("Button", {
      //   class: 'font-blue',
      //   props: {
      //     size: "small",
      //     type: 'text'
      //   },
      //   on: {
      //     click: () => {
      //       bus.$emit("onChangePause", { item: row })
      //     }
      //   }
      // }, '暂停');
      // let cancelPauseBtn = h("Button", {
      //   class: 'font-blue',
      //   props: {
      //     size: "small",
      //     type: 'text'
      //   },
      //   on: {
      //     click: () => {
      //       bus.$emit("onChangePause", { item: row })
      //     }
      //   }
      // }, '取消暂停');
      // let deleteBtn = h("Button", {
      //   class: 'font-blue',
      //   props: {
      //     size: "small",
      //     type: 'text'
      //   },
      //   style:{
      //       display: row.activityTypeEnum == 'FULL_COUPON' ? "none": 'inline-block',
      //   },
      //   on: {
      //     click: () => {
      //       bus.$emit("onDelete", { item: row, index: params.index })
      //     }
      //   }
      // }, '删除')
      
      // let auditBtn = h("Button", {
      //   class: 'font-blue',
      //   props: {
      //     size: "small",
      //     type: 'text'
      //   },
      //   on: {
      //     click: () => {
      //       window.$router.push({
      //         name: "sales/detail",
      //         query: {
      //           id: row.id,
      //           type: row.activityTypeEnum
      //         }
      //       })
      //     }
      //   }
      // }, '审核');
      // let totalBtn = h("Button", {
      //   props: {
      //     size: "small",
      //     type: 'primary'
      //   },
      //   on: {
      //     click: () => {
      //       window.$router.push({
      //         name: "sales/statics",
      //         query: {
      //           id: row.id
      //         }
      //       });
      //     }
      //   }
      // }, '数据统计');
      // 所有的 查看，统计，删除，复制 都有
      // 修改：未开始, 驳回的时候显示，其他都不显示
      // 审核：未审核，其他都没有
      // 暂停：是否已暂停，取消暂停
      // 满额返券，没有删除，没有修改，其他都有      
      // 满额返券，没有删除，没有修改，其他都有
      // 满额返券，没有删除，没有修改，其他都有
      // 编辑 下架并且未驳回 || 未开始
      // if (row.statusText === '未审核') {
      //   let button = [detailBtn, auditBtn, deleteBtn, totalBtn,  shelfBtn, copyBtn]
      //   if (row.shelfStatusEnum === "UNDER" || row.promotionTypeDescription === '工厂特价') button.push(editBtn)
      //   return h("div", button);
      // } else if (row.statusText === '已驳回') {
      //   return h("div", [detailBtn, deleteBtn, copyBtn]);
      // } else if (row.statusText === '已暂停') {
      //   let button = [detailBtn, cancelPauseBtn, deleteBtn, totalBtn, shelfBtn, copyBtn]
      //   if (row.shelfStatusEnum === "UNDER" || row.promotionTypeDescription === '工厂特价') button.push(editBtn)
      //   return h("div", button);
      // } else if (row.statusText === '未开始') {
      //   return h("div", [detailBtn, deleteBtn, totalBtn, editBtn, shelfBtn, copyBtn]);
      // } else if (row.statusText === '进行中') {
      //   let button  = [detailBtn, pauseBtn, totalBtn, shelfBtn, copyBtn]
      //   if (row.shelfStatusEnum === "UNDER" || row.promotionTypeDescription === '工厂特价') button.push(editBtn)
      //   return h("div", button);
      // } else if (row.statusText === '已结束') {
      //   let button = [detailBtn, deleteBtn, totalBtn, shelfBtn, copyBtn]
      //   if (row.shelfStatusEnum === "UNDER" || row.promotionTypeDescription === '工厂特价') button.push(editBtn)
      //   return h("div", button)
      // } else if (row.promotionTypeDescription === '满额返券') {
      //   return h("div", [detailBtn, totalBtn, shelfBtn, copyBtn]);
      // } else if (row.statusText === '下架') {
      //   return h("div", [detailBtn, deleteBtn, totalBtn, editBtn, shelfBtn, copyBtn]);
      // }
      return h('div', [detailBtn, copyBtn, drop])
    }
  }],
  data: []
}

export default data;